﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ListAllCustomerInfo.aspx.cs"
    Inherits="ZX.WebApp.Crm.Report.ListAllCustomerInfo" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../../Scripts/yui_2.9.0/build/reset-fonts-grids/reset-fonts-grids.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/container/assets/skins/sam/container.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/yui_2.9.0/build/menu/assets/skins/sam/menu.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/button/assets/skins/sam/button.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/layout/assets/skins/sam/layout.css" />
    <link rel="stylesheet" type="text/css" href="../../scripts/yui_2.9.0/build/resize/assets/skins/sam/resize.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/yui_2.9.0/build/datatable/assets/skins/sam/datatable.css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/yui_2.9.0/build/fonts/fonts-min.css" />
    <link href="../../Scripts/JQuery_zTree_v3.3/css/zTreeStyle/zTreeStyle.css" rel="stylesheet"
        type="text/css" />
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/element/element-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/datasource/datasource-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/json/json-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/get/get-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/dragdrop/dragdrop-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/datatable/datatable-min.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/paginator/paginator-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/layout/layout-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/button/button-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/container/container-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/resize/resize-min.js"></script>
    <script type="text/javascript" src="../../scripts/yui_2.9.0/build/event-delegate/event-delegate-min.js"></script>
    <script src="../../Scripts/Public.js" type="text/javascript"></script>
    <script src="../../Scripts/JQuery_zTree_v3.3/js/jquery-1.4.4.min.js" type="text/javascript"></script>
    <script src="../../Scripts/JQuery_zTree_v3.3/js/jquery.ztree.all-3.3.min.js" type="text/javascript"></script>
    <script src="../../Scripts/JQuery_zTree_v3.3/js/jquery.ztree.core-3.3.min.js" type="text/javascript"></script>
    <script src="../../Scripts/JQuery_zTree_v3.3/js/jquery.ztree.excheck-3.3.min.js"
        type="text/javascript"></script>
</head>
<script type="text/javascript">
    var funcid = getPar1("functionID");
    (function () {
        var t = "<%=ReturnNoData %>";
        var Dom = YAHOO.util.Dom,
        Event = YAHOO.util.Event;
        Event.onDOMReady(function () {
            //屏蔽右键
            if (typeof (parent.unContextMenu) == "function") {
                parent.unContextMenu(document);
            }
            if (typeof (parent.parent.unContextMenu) == "function") {
                parent.parent.unContextMenu(document);
            }

            var layout = new YAHOO.widget.Layout({
                units: [
                { position: 'center', scroll: true}]
            });
            var layout2;
            layout.on('render', function () {
                var el = layout.getUnitByPosition('center').get('wrap');
                layout2 = new YAHOO.widget.Layout(el, {
                    parent: layout,
                    units: [
                            { position: 'left', header: '用户列表', body: 'fieldLeft', gutter: '0 1 1 1',
                                width: 170, minWidth: 170, collapse: true, scroll: true, animate: true
                            },
                            { position: 'center', header: '客户信息', body: 'fieldRight', gutter: '0 1 1 1' }
                        ]
                });
                layout2.render();
            });
            layout.render();

            if (t == "0")
                layout2.getUnitByPosition('left').close();
            //树形数据初始化
            $.post("ListAllCustomerInfo.aspx?r=" + Math.random(), { "Action": "InitTree", "functionID": funcid }, function (result) {
                if (result != undefined && result[0].error != "true")
                    $.fn.zTree.init($("#treeDemo"), setting, result);
            });
            funcid = getPar1("functionID")
            var src = "RptAllCustomerInfo.aspx?entity=V_CrmCustomerInfo&order=Code desc&functionID=" + funcid;
            $("#mainFrame").attr("src", src);
        }, "json");
    })();

    //异步加载树
    var setting = {
        view: {
            showIcon: showIconForTree
        },
        async: {
            enable: true,
            url: getUrl
        },
        check: {
            enable: false
        },
        data: {
            key: {
                key1: "key1",
                key2: "key2"
            },
            simpleData: {
                enable: true
            }
        },
        view: {
            expandSpeed: ""
        },
        callback: {
            beforeExpand: beforeExpand,
            onAsyncSuccess: onAsyncSuccess,
            onAsyncError: onAsyncError,
            beforeClick: beforeClick,
            onClick: onClick
        }
    };

    var className = "dark";
    function getUrl(treeId, treeNode) {
        var k1 = treeNode.key1;
        var param;
        if (k1 == "dept")
            param = "Action=loadtree&id=" + treeNode.id + "&functionID=" + funcid;
        if (k1 == "user") {
            var k2 = treeNode.key2;
            param = "Action=loadcustom&id=" + treeNode.id + "&CustomUser=" + k2 + "&functionID=" + funcid;
        }

        return "ListAllCustomerInfo.aspx?" + param;
    };

    function beforeExpand(treeId, treeNode) {
        if (!treeNode.isAjaxing) {
            startTime = new Date();
            treeNode.times = 1;
            ajaxGetNodes(treeNode, "refresh");
            return true;
        } else {
            alert("正在下载数据中，请稍后展开节点。。。");
            return false;
        }
    };

    function onAsyncSuccess(event, treeId, treeNode, msg) {
        if (!msg || msg.length == 0) {
            return;
        }
        var zTree = $.fn.zTree.getZTreeObj("treeDemo"),
			totalCount = treeNode.count;
        if (treeNode.children.length < totalCount) {
            setTimeout(function () { ajaxGetNodes(treeNode); }, perTime);
        } else {
            treeNode.icon = "";
            zTree.updateNode(treeNode);
            zTree.selectNode(treeNode.children[0]);
            endTime = new Date();
            className = (className === "dark" ? "" : "dark");
        }
    }
    function onAsyncError(event, treeId, treeNode, XMLHttpRequest, textStatus, errorThrown) {
        //        var zTree = $.fn.zTree.getZTreeObj("treeDemo");
        //        alert("异步获取数据出现异常。");
        //        treeNode.icon = "";
        //        zTree.updateNode(treeNode);
        treeNode.icon = ""; ;
    }
    function ajaxGetNodes(treeNode, reloadType) {
        var zTree = $.fn.zTree.getZTreeObj("treeDemo");
        if (reloadType == "refresh") {
            treeNode.icon = "../../Scripts/JQuery_zTree_v3.3/css/zTreeStyle/img/loading.gif";
            zTree.updateNode(treeNode);
        }
        zTree.reAsyncChildNodes(treeNode, reloadType, true);
    }

    $(document).ready(function () {

    });
    function beforeClick(treeId, treeNode, clickFlag) {
        className = (className === "dark" ? "" : "dark");
        return (treeNode.click != false);
    }
    function onClick(event, treeId, treeNode, clickFlag) {
        var k1 = treeNode.key1;
        var k2 = treeNode.key2;
        var url = "";
        var funcid = getPar1("functionID");
        if (k1 == "dept")
            url = "RptAllCustomerInfo.aspx?entity=V_CrmCustomerInfo&order=Code desc&functionID=" + funcid + "&condition=CustomUser in(select  userid  from fn_GetOrganizeUser('" + treeNode.id + "'))";
        if (k1 == "user")
            url = "RptAllCustomerInfo.aspx?entity=V_CrmCustomerInfo&order=Code desc&functionID=" + funcid + "&condition=CustomUser='" + k2 + "'";
        if (k1 == "custom")
            url = "RptAllCustomerInfo.aspx?entity=V_CrmCustomerInfo&order=Code desc&functionID=" + funcid + "&condition=" + k2;
        $("#mainFrame").attr("src", url);
    }
    function showIconForTree(treeId, treeNode) {
        return !treeNode.isParent;
    }
</script>
<body class="yui-skin-sam">
    <form id="form1" runat="server">
    <div class="fieldForm" id="fieldForm" style="display: none;">
        <div id="fieldLeft" style="height: 100%; overflow-y: scroll;">
            <ul id="treeDemo" class="ztree">
            </ul>
        </div>
        <div id="fieldRight" style="height: 99.5%;">
            <iframe src="#" width="100%" height="100%" id="mainFrame" frameborder="0" name="mainFrame">
            </iframe>
        </div>
    </div>
    </form>
</body>
</html>
